package com.mjk.common.ai.service;


import com.mjk.common.ai.dto.ConvPresetRelDto;
import com.mjk.common.ai.entity.ConversationPresetRel;
import com.mjk.common.ai.util.MPPageUtil;
import com.mjk.common.core.jdbc.bean.BeePage;
import com.mjk.common.core.jdbc.service.plus.idbservice.BeeDBService;
import com.mjk.common.core.jdbc.service.plus.wrap.BeeQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class ConversationPresetRelService {

    @Autowired
    private BeeDBService beeDBService;

    public List<ConvPresetRelDto> listByUser(Long userId, Integer limit) {
        BeeQueryWrapper wrapper = new BeeQueryWrapper(ConversationPresetRel.class);
        wrapper
                .eq(ConversationPresetRel::getUserId, userId)
                .eq(ConversationPresetRel::getIsDeleted, false)
                .setPage(0, limit);
        BeePage<ConversationPresetRel> list = beeDBService.findManyByWrapperWithPage(wrapper);
        return MPPageUtil.convertToList(list.getList(), ConvPresetRelDto.class);
    }

    public boolean softDelBy(Long userId, Long convId) {
        ConversationPresetRel rel = new ConversationPresetRel();
        rel.setIsDeleted(true);
        BeeQueryWrapper wrapper = new BeeQueryWrapper(rel);
        wrapper
                .eq(ConversationPresetRel::getUserId, userId)
                .eq(ConversationPresetRel::getUserConvId, convId);
        return beeDBService.update(wrapper) > 0;
    }
}
